<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:fn="http://java.sun.com/jsp/jstl/functions"
	xmlns:p="http://primefaces.org/ui"
	xmlns:c="http://java.sun.com/jsp/jstl/core"	
	xmlns:cc="http://java.sun.com/jsf/composite"	>

<cc:interface componentType="org.primefaces.component.Row" preferred="true" shortDescription="Schedule Row">
	<cc:attribute 	name="baseYear" 			type="java.lang.Integer" 											required="true" 	/>
	<cc:attribute 	name="cycleType" 			type="com.hemerasolutions.v2trainer.model.schedule.CycleType"		required="true"  	/>
	<cc:attribute 	name="rowIcon" 				type="java.lang.String"												default="none"  	/>
	<cc:attribute 	name="removable" 			type="java.lang.Boolean"											default="true"  	/>
	<cc:attribute 	name="editable" 			type="java.lang.Boolean"											default="true"  	/>

	<cc:attribute 	name="handlerBean"			type="java.lang.Object"/>

	<cc:attribute 	name="selectedCycle" 			type="com.hemerasolutions.v2trainer.model.schedule.Cycle"		required="true"/>
	
	<cc:facet 		name="contextForRow" 		/>
	<cc:facet 		name="contextForTitle" 		/>

</cc:interface>

<cc:implementation>
	<cc:actionSource name="#{component}">
		<p:column colspan="#{cc.attrs.editable and cc.attrs.removable ? 1 : (cc.attrs.editable or cc.attrs.removable ? 2 : 1) }">
			<p:outputLabel  value="#{cc.attrs.cycleType.name}"/> 							
		</p:column>
		<p:column colspan="1"  styleClass="ui-table-button-column" rendered="#{cc.attrs.editable}"> 
			<p:commandButton id="buttonCycleType" actionListener="#{cc.attrs.handlerBean.handleCycleType}" icon="ui-icon-pencil" styleClass="ui-table-button">
				<f:attribute name="cycleType"  	value="#{cc.attrs.cycleType}"  />
			</p:commandButton>
		</p:column>
		<p:column colspan="1"  styleClass="ui-table-button-column" rendered="#{cc.attrs.removable}"> 
			<p:commandButton icon="ui-icon-trash" styleClass="ui-table-button" />
		</p:column>
		
		<c:forEach var="cycle" items="#{scheduleCompositeBean.cycles}">

			<p:column colspan="#{cycle.endWeek - cycle.begWeek}" styleClass="ui-table-button-column"   >
				<p:commandButton actionListener="#{cc.attrs.handlerBean.handleCycle}" value="#{cycle.name}" styleClass="ui-table-button" icon="#{cc.attrs.rowIcon}">
					<f:attribute name="cycleType"  	value="#{cc.attrs.cycleType}"  />
					<f:attribute name="cycle"  		value="#{cycle}"  />
				</p:commandButton>
			</p:column>						
	
		</c:forEach>
	</cc:actionSource>		
</cc:implementation>


</html>